home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / FieldList.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  5KB  |  217 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/FieldList.c,v 41.11 2000/05/09 20:33:30 mlemos Exp $
  3.  *
  4.  * FieldList.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995-1996 Jaba Development.
  8.  * (C) Copyright 1995-1996 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * This example is a bit more complicated. It will
  12.  * open a window with two listviews. The left-one
  13.  * is a sortable listview which will automatically
  14.  * sort the entries which are dropped on it.
  15.  *
  16.  * The right listview allows you to position the
  17.  * dropped entries.
  18.  *
  19.  * This demonstration uses the listview subclass
  20.  * as defined in the "fieldlist.h" file.
  21.  *
  22.  * $Log: FieldList.c,v $
  23.  * Revision 41.11  2000/05/09 20:33:30  mlemos
  24.  * Bumped to revision 41.11
  25.  *
  26.  * Revision 1.2  2000/05/09 19:58:49  mlemos
  27.  * Merged with the branch Manuel_Lemos_fixes.
  28.  *
  29.  * Revision 1.1.2.1  1998/02/28 17:45:12  mlemos
  30.  * Ian sources
  31.  *
  32.  *
  33.  */
  34.  
  35. /* Execute me to compile with DICE V3.0.
  36. dcc FieldList.c -proto -mi -ms -mRR -3.0 -lbgui
  37. quit
  38. */
  39.  
  40. #include "DemoCode.h"
  41. #include "FieldList.h"
  42.  
  43. #include <graphics/gfxbase.h>
  44. #include <string.h>
  45.  
  46. /*
  47.  *    Just a bunch of entries like the
  48.  *    ones found in the SnoopDos 3.0
  49.  *    Format Editor.
  50.  *
  51.  *    This does not have to be sorted since the
  52.  *    class will do this for us.
  53.  */
  54. STATIC UBYTE *entries[] = {
  55.     "CallAddr\t%c",
  56.     "Date\t%d",
  57.     "Hunk:Offset\t%h",
  58.     "Task ID\t%i",
  59.     "Segment Name\t%s",
  60.     "Time\t%t",
  61.     "Count\t%u",
  62.     "Process Name\t%p",
  63.     "Action\t%a",
  64.     "Target Name\t%n",
  65.     "Options\t%o",
  66.     "Res.\t%r",
  67.     NULL
  68. };
  69.  
  70. /*
  71.  *    Object ID's
  72.  */
  73. #define ID_QUIT         1
  74.  
  75. extern struct GfxBase        *GfxBase;
  76.  
  77. /*
  78.  *    Here we go...
  79.  */
  80. VOID StartDemo( void )
  81. {
  82.     struct Window            *window;
  83.     struct TextAttr                  fixed;
  84.     UBYTE                 fname[ 32 ];
  85.     Object                *WO_Window, *GO_ListSorted, *GO_ListPlace;
  86.     ULONG                 signal, rc;
  87.     Class                *class;
  88.     BOOL                 running = TRUE;
  89.     
  90.     ULONG                 weights[] = { 50, 5 };
  91.  
  92.     /*
  93.      *    Close your eyes! This is very ugly code and should
  94.      *    not be regarded as good programming practice!
  95.      *
  96.      *    Do not use this kind of code in serious programs. I
  97.      *    just did this to keep it simple.
  98.      */
  99.     Forbid();
  100.     strcpy( fname, GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name );
  101.     fixed.ta_Name    = fname;
  102.     fixed.ta_YSize    = GfxBase->DefaultFont->tf_YSize;
  103.     fixed.ta_Style    = GfxBase->DefaultFont->tf_Style;
  104.     fixed.ta_Flags    = GfxBase->DefaultFont->tf_Flags;
  105.     Permit();
  106.  
  107.     /*
  108.      *    Initialize the class.
  109.      */
  110.     if ( class = InitFLClass()) {
  111.         /*
  112.          *    Build the window object tree.
  113.          */
  114.         WO_Window = WindowObject,
  115.             WINDOW_Title,            "Listview Drag-n-Drop",
  116.             WINDOW_ScaleWidth,    25,
  117.             WINDOW_ScaleHeight,    15,
  118.             WINDOW_RMBTrap,        TRUE,
  119.             WINDOW_AutoAspect,    TRUE,
  120.             WINDOW_AutoKeyLabel,    TRUE,
  121.             WINDOW_MasterGroup,
  122.                 VGroupObject, HOffset(6), VOffset(6), Spacing(6),
  123.                     StartMember,
  124.                         InfoFixed( NULL, ISEQ_C "Field selection using\nListview Drag-n-Drop.", NULL, 2 ), FixMinHeight,
  125.                     EndMember,
  126.                     StartMember,
  127.                         HGroupObject, Spacing(6),
  128.                             StartMember,
  129.                                 /*
  130.                                  *    Create a auto-sort draggable and
  131.                                  *    droppable FL class object.
  132.                                  */
  133.                                 GO_ListSorted = NewObject( class, NULL, LAB_Label,        "Available Fields",
  134.                                                     LAB_Place,                    PLACE_ABOVE,
  135.                                                     LISTV_EntryArray,            entries,
  136.                                                     LISTV_SortEntryArray,    TRUE,
  137.                                                     LISTV_Columns,                2,
  138.                                                     LISTV_ColumnWeights,        weights,
  139.                                                 //    LISTV_ListFont,         &fixed,
  140.                                                     FL_SortDrops,                TRUE,
  141.                                                     BT_DragObject,                TRUE,
  142.                                                     BT_DropObject,                TRUE,
  143.                                                     TAG_END ),
  144.                             EndMember,
  145.                             StartMember,
  146.                                 /*
  147.                                  *    Create a draggable and dropable
  148.                                  *    FL class object which allows positioning
  149.                                  *    the drops.
  150.                                  */
  151.                                 GO_ListPlace = NewObject( class, NULL, LAB_Label,        "Current Format",
  152.                                                        LAB_Place,        PLACE_ABOVE,
  153.                                                        LISTV_ShowDropSpot,    TRUE,
  154.                                                   //     LISTV_Columns,        2,
  155.                                                 //        LISTV_ColumnWeights,        weights,
  156.                                                    //  LISTV_ListFont,           &fixed,
  157.                                                        BT_DragObject,        TRUE,
  158.                                                        BT_DropObject,        TRUE,
  159.                                                        TAG_END ),
  160.                             EndMember,
  161.                         EndObject,
  162.                     EndMember,
  163.                     StartMember,
  164.                         HGroupObject,
  165.                             VarSpace( DEFAULT_WEIGHT ),
  166.                             StartMember, FuzzButton( "_Quit", ID_QUIT ), EndMember,
  167.                             VarSpace( DEFAULT_WEIGHT ),
  168.                         EndObject, FixMinHeight,
  169.                     EndMember,
  170.                 EndObject,
  171.         EndObject;
  172.  
  173.         /*
  174.          *    Window object tree OK?
  175.          */
  176.         if ( WO_Window ) {
  177.             /*
  178.              *    Tell the FL class objects to accept
  179.              *    drops from eachother.
  180.              */
  181.             SetAttrs( GO_ListSorted, FL_AcceptDrop, GO_ListPlace,  TAG_END );
  182.             SetAttrs( GO_ListPlace,  FL_AcceptDrop, GO_ListSorted, TAG_END );
  183.  
  184.             /*
  185.              *    Open the window.
  186.              */
  187.             if ( window = WindowOpen( WO_Window )) {
  188.                 /*
  189.                  *    Get signal wait mask.
  190.                  */
  191.                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  192.  
  193.                 do {
  194.                     Wait( signal );
  195.  
  196.                     /*
  197.                      *    Handle messages.
  198.                      */
  199.                     while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  200.                         switch ( rc ) {
  201.                             case    WMHI_CLOSEWINDOW:
  202.                             case    ID_QUIT:
  203.                                 running = FALSE;
  204.                                 break;
  205.                         }
  206.                     }
  207.                 } while ( running );
  208.             } else
  209.                 Tell( "Unable to open the window.\n" );
  210.             DisposeObject( WO_Window );
  211.         } else
  212.             Tell( "Unable to create the window object.\n" );
  213.         FreeClass( class );
  214.     } else
  215.         Tell( "Unable to initialize the FL class.\n" );
  216. }
  217.